package com.xiaoshuidi.cloud.module.member.controller.app.topics;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.member.controller.admin.topics.vo.TopicListVO;
import com.xiaoshuidi.cloud.module.member.controller.admin.topics.vo.TopicsDetailVo;
import com.xiaoshuidi.cloud.module.member.controller.admin.topics.vo.TopicsPageVO;
import com.xiaoshuidi.cloud.module.member.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.member.service.topics.MemberTopicsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

@Tag(name = "租客APP - 话题")
@RestController
@RequestMapping(ApiConstants.NAME + "/topics")
@Validated
public class AppMemberTopicsController {
    @Resource
    private MemberTopicsService memberTopicsService;

    @PostMapping("/get-page")
    @Operation(summary = "手机获得话题列表")
    @PermitAll
    public CommonResult<PageResult<TopicListVO>> getAppPage(@Valid @RequestBody TopicsPageVO pageVO) {
        PageResult<TopicListVO> pageResult = memberTopicsService.getAppPage(pageVO);
        return success(pageResult);
    }

    @GetMapping("/get-by-id/{id}")
    @Operation(summary = "查看话题详情")
    @PermitAll
    public CommonResult<TopicsDetailVo> getById(@PathVariable("id") Long id) {
        return success(memberTopicsService.getById(id));
    }

}
